<template>
  <div class="app-container">

    <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="kind" label="类别" width="80" />


      <el-table-column prop="title" label="标题" />

      <el-table-column prop="gmtCreate" label="添加时间" width="160"/>

      <el-table-column prop="sort" label="排序" width="60" />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/article/update/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit" >修改</el-button>
          </router-link>
          <el-button type="success" size="mini" icon="el-icon-share" @click="pushById(scope.row.id)">推送</el-button>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- scope.row.id 获取该行内容的id -->

    <!-- 分页 -->
    <!-- 需要修改的地方@current-change="getList"  -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
  </div>
</template>
<script>
import article from "@/api/article/article"
export default{
  data(){
    return{
      list:null,//查询后的接口集合
      page:1,//当前页
      limit:10,//每页记录总数
      total:0,//总记录数
      input: ''
    }
  },
  created(){
    this.getList()
  },
  methods:{
    getList(page=1){
      this.page=page
      article.pageArticle(this.page,this.limit)
        .then(response=>{
          this.list=response.data.rows
          this.total=response.data.total
        })
    },
    removeDataById(id){
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        article.deleteArticleById(id)
          .then(response=>{
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          })
        //刷新页面
        this.getList();
      })
    },
    pushById(id){
        article.push(id)
          .then(response=>{
            this.$message({
              type: 'success',
              message: '推送成功!'
            });
          })
    },
    updateById(id){
      this.$router.push({path:'/article/update'})
    },
  }
}
</script>
